package cn.lstest.flutter_bluetooth

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
	private val CHANNEL = "cn.lstest.flutter_bluetooth/native_sdk"

	override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
		super.configureFlutterEngine(flutterEngine)

		MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
			when (call.method) {
				"checkNativeClasses" -> {
					val classNames = call.argument<List<String>>("classes") ?: emptyList()
					val availability = mutableMapOf<String, Boolean>()
					for (cn in classNames) {
						availability[cn] = try {
							Class.forName(cn)
							true
						} catch (e: ClassNotFoundException) {
							false
						}
					}
					result.success(availability)
				}
				else -> result.notImplemented()
			}
		}
	}
}
